package com.equipment;

import com.util.EncodingUtil;

/**
 * 卡片命令通道 FDA2
 *
 * @version 1.18
 * @author 刘亚东
 */
public class CardCommandChannelRequest {
	private String STX = "55AA"; // 帧开始标志
	private String RSCTL = "00"; // 串口帧序列号
	private String Length="";//长度
	private String code = "FD"; // 代码
	private String broadening = "A2"; // 扩展代码
	private String BCC = ""; // 异或校验值
	// PSAM卡号（1~4），接触式大卡号 0，非接触卡号0xff
	private String PsamNum = "";
	// 数据长度
	private String PsamCmdRqLen = "";
	// 数据
	private String PsamCmdRqData = "";

	/**
	 * 发送FDA2指令(卡片命令通道)
	 *
	 * @param pasmNum
	 * @param len
	 * @param data
	 * @return
	 */
	public String command(String pasmNum, String data) {
		this.PsamNum = EncodingUtil.desToHex(Integer.parseInt(pasmNum), 2); // PSAM卡号（1~4），接触式大卡号															// 0，非接触卡号0xff
		this.PsamCmdRqLen = EncodingUtil.desToHex(data.length()/2, 2); // 数据长度
		this.PsamCmdRqData = data; // 数据
		//计算长度
		Length=EncodingUtil.desToHex((broadening+PsamNum+PsamCmdRqLen+PsamCmdRqData).length()/2, 4);
		// 异或校验从RSCTL到DATA所有字节的异或值
		String DATA = RSCTL+Length+code + broadening + PsamNum + PsamCmdRqLen
				+ PsamCmdRqData;
		// 异或校验从RSCTL到DATA所有字节的异或值
		BCC = EncodingUtil.yihuo(EncodingUtil.change(DATA));
		// 拼接完整的请求
		String retn = STX + DATA + BCC;
		return retn;
	}

	public String getSTX() {
		return STX;
	}

	public void setSTX(String sTX) {
		STX = sTX;
	}

	public String getRSCTL() {
		return RSCTL;
	}

	public void setRSCTL(String rSCTL) {
		RSCTL = rSCTL;
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getBroadening() {
		return broadening;
	}

	public void setBroadening(String broadening) {
		this.broadening = broadening;
	}

	public String getBCC() {
		return BCC;
	}

	public void setBCC(String bCC) {
		BCC = bCC;
	}

	public String getPsamNum() {
		return PsamNum;
	}

	public void setPsamNum(String psamNum) {
		PsamNum = psamNum;
	}

	public String getPsamCmdRqLen() {
		return PsamCmdRqLen;
	}

	public void setPsamCmdRqLen(String psamCmdRqLen) {
		PsamCmdRqLen = psamCmdRqLen;
	}

	public String getPsamCmdRqData() {
		return PsamCmdRqData;
	}

	public void setPsamCmdRqData(String psamCmdRqData) {
		PsamCmdRqData = psamCmdRqData;
	}

	public String getLength() {
		return Length;
	}

	public void setLength(String length) {
		Length = length;
	}

}
